package com.huike.review.controller;

import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.review.domain.Review;
import com.huike.review.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/review")
public class ReviewController extends BaseController {
    @Autowired
    ReviewService reviewService;
    @GetMapping("/saveData/{name}/{age}/{sex}")
    public AjaxResult saveData1(@PathVariable("name") String name,
                                @PathVariable("age") Integer age,
                                @PathVariable("sex") String sex) {
        reviewService.saveReview(name, age, sex);
        return AjaxResult.success("成功插入：1条数据");
    }

    @PostMapping("/saveData")
    public AjaxResult saveData2(@RequestBody Review review){
        reviewService.saveReviews(review);
        return AjaxResult.success("成功插入：1条数据");
    }

    @DeleteMapping("/remove/{id}")
    public AjaxResult removeData(@PathVariable Integer id){
        reviewService.removeById(id);
        return AjaxResult.success("成功删除：1条数据");
    }

    @PostMapping("/update")
    public AjaxResult updateData(@RequestBody Review review){
        reviewService.updateById(review);
        return AjaxResult.success("成功修改：1条数据");
    }
    @GetMapping("/getById")
    public AjaxResult selectById(@RequestParam("id") Integer id){
        Review reviews = reviewService.selectById(id);
        return AjaxResult.success("操作成功",reviews);
    }

    @GetMapping("/getDataByPage")
    public TableDataInfo selectByPage(){
        startPage();
        List<Review> reviews = reviewService.selectByPage();
        return getDataTablePage(reviews);
    }
}
